<?php
class ContextsController extends AppController {

	var $name = 'Contexts';

	function admin_index() {
		$this->Context->recursive = 0;
		$this->set('contexts', $this->paginate());
	}

	function admin_view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid context', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('context', $this->Context->read(null, $id));
	}

	function admin_add() {
		if (!empty($this->data)) {
			$this->Context->create();
			if ($this->Context->save($this->data)) {
				$this->Session->setFlash(__('The context has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The context could not be saved. Please, try again.', true));
			}
		}
		$suggestions = $this->Context->Suggestion->find('list');
		$widgets = $this->Context->Widget->find('list');
		$widgets = $this->Context->Widget->find('list');
		$this->set(compact('suggestions', 'widgets', 'widgets'));
	}

	function admin_edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid context', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Context->save($this->data)) {
				$this->Session->setFlash(__('The context has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The context could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Context->read(null, $id);
		}
		$suggestions = $this->Context->Suggestion->find('list');
		$widgets = $this->Context->Widget->find('list');
		$widgets = $this->Context->Widget->find('list');
		$this->set(compact('suggestions', 'widgets', 'widgets'));
	}

	function admin_delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for context', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Context->delete($id)) {
			$this->Session->setFlash(__('Context deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Context was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
?>